package nl.ordina.ott.java.client;

import nl.ordina.ott.java.client.model.Oplosser;
import nl.ordina.ott.java.client.model.Speelveld;
import nl.ordina.ott.java.client.model.Vakje;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Sudoku implements EntryPoint {
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		final Button stepButton = new Button("Los een stap op");
		
		stepButton.addClickHandler(new ClickHandler() {
			private int aantalKerenGeclickt = 0;
			public void onClick(ClickEvent e) {
				if (aantalKerenGeclickt == 0) {
					Oplosser.getOplosser().initialiseerSpeelveld();
				}
				Oplosser.getOplosser().losStapOp();
				aantalKerenGeclickt++;
			}
		});
		
		
		
		final Button solutionButton = new Button("Los alles op");
		
		solutionButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent e) {
				Oplosser.getOplosser().losAllesOp();
			}
		});

		Speelveld speelveld = new Speelveld();
		FlexTable flexTable = new FlexTable();

		stepButton.removeStyleName("gwt-Button");
		stepButton.addStyleName("stepButton");
		solutionButton.removeStyleName("gwt-Button");
		solutionButton.addStyleName("solutionButton");

		for (int rij = 0; rij < 9; rij++) {
			for (int kolom = 0; kolom < 9; kolom++) {
				
				Vakje vakje = speelveld.getVakje(rij+1, kolom+1);
				vakje.removeStyleName("gwt-TextBox");
				vakje.addStyleName("sudoku-TextBox");
				flexTable.setWidget(rij, kolom, vakje);
			}
		}
		for (int i = 0; i < 9; i++) {
			flexTable.getFlexCellFormatter().addStyleName(i, 3, "dikkelijn");
			flexTable.getFlexCellFormatter().addStyleName(i, 6, "dikkelijn");
		}
		flexTable.getRowFormatter().addStyleName(3, "dikkelijn");
		flexTable.getRowFormatter().addStyleName(6, "dikkelijn");

		RootPanel.get().add(flexTable);
		RootPanel.get().add(stepButton);
		RootPanel.get().add(solutionButton);

	}
}
